package maze.levels;

import java.awt.Graphics2D;
import maze.Cell;
import maze.Game;
import maze.Game.State;
import maze.Maze;

/**
 *
 * @author Dennis Nijssen
 */
public class Player {
    private Animal animal;
    private Maze maze;
    private int x, y;
    private int prevX, prevY;
    
    public Player(Maze maze, Animal animal, int x, int y) {        
        this.maze = maze;
        this.animal = animal;
        
        this.x = x;
        this.y = y;
    }
    
    public void moveUp() {
        if(!getCurrentCell().getNorth()) {
            prevY = y;
            prevX = x;
            y--;
        }
        
        //checkForQuestion();
    }
    
    public void moveDown() {
        if(!getCurrentCell().getSouth()) {
            prevY = y;
            prevX = x;
            y++;
        }
        
        //checkForQuestion();
    }
    
    public void moveLeft() {
        if(!getCurrentCell().getWest()) {
            prevX = x;
            prevY = y;
            x--;
        }
        
        //checkForQuestion();
    }
    
    public void moveRight() {
        if(!getCurrentCell().getEast()) {
            prevX = x;
            prevY = y;
            x++;
        }
        
        //checkForQuestion();
    }
    
    public Cell getPreviousCell() {
        return maze.getCellAt(prevX, prevY);
    }
    public Cell getCurrentCell() {
        return maze.getCellAt(x, y);
    }
    
    public boolean hitQuestion() {
        if(getCurrentCell().hasQuestion()) {
            return !(getCurrentCell().getQuestion().getVisited());
        }
        return false;
    }
    
    public boolean hitKnowledge() {
        if(getCurrentCell().hasKnowledge()) {
            //If the question has not been answered yet.
            return !(getCurrentCell().getKnowledge().getVisited());
        }
        return false;
    }
    
    public void playAudio() {
        animal.playAudio();
    }
    /**
     * Checks for a question on the current cell. If the current cell contains
     * a question then change the Game.STATE variable
     */
    /*private void checkForQuestion() {
        if(getCurrentCell().hasQuestion()) {
            //If the question has not been answered yet.
            if(!getCurrentCell().getQuestion().getVisited()) {
                Game.STATE = State.QUESTION;
                animal.playAudio();
            }
        }
        if(getCurrentCell().hasKnowledge()) {
            if(!getCurrentCell().getKnowledge().getVisited()) {
                Game.STATE = State.KNOW_IT_ALL;
            }
        }
    }*/
    
    public void paint(Graphics2D g2d, double scaleX, double scaleY) {
        this.animal.paint(g2d, x, y, scaleX, scaleY);
    }
}
